var categoryPage = avalon.define({
	$id: "categoryPage",
	banners: {},
	categorys: []
});
mui.ready(function() {
	var slider = mui("#slider");
	mui.init({
		pullRefresh: {
			container: "#category",
			down: {
				height: 50,
				auto: true,
				contentdown: $.i18n.prop('Pull_down_to_refresh'),
				contentover: $.i18n.prop('Release_to_immediate_refresh'),
				contentrefresh: $.i18n.prop('Loading'),
				callback: function() {
					setTimeout(function() {
						mui.ajax('/solution/index.json', {
							dataType: 'json',
							success: function(data) {
								var banners = {};
								if(data.banners.length > 0) {
									$("#slider").removeClass("mui-hidden");
									var interval=0;
									if(data.banners.length==1){
										banners['first'] = data.banners[0];
										banners['last'] = data.banners[0];
									}else{
										avalon.each(data.banners, function(i, banner) {
											if(0 == i) {
												banners['first'] = banner;
											} else if(data.banners.length == i + 1) {
												banners['last'] = banner;
											}
										});
										interval=3000;
									}
									
									banners['items'] = data.banners;
									categoryPage.banners = banners;
									
									slider.slider({
										interval: interval
									});
									
								}else{
									$("#slider").addClass("mui-hidden");
								}
								
								
								categoryPage.categorys = data.categorys;
							},
                                 complete:function(){
                                     mui(".solution_box div a").each(function(){
                                          $(this).css("height",($("#category").height()-160-7)/4);
                                    });
                                 }
						});
						mui('#category').pullRefresh().endPulldownToRefresh();
					}, window.DAHUA_CONFIG.LOADING_TIME);
				}
			}
		}
	});

	mui(".solution_box").on('tap', 'a', function() {
		var cid = this.getAttribute('data-id');
		var url = this.getAttribute('href');
		mui.openWindow({
			url: url + "?cid=" + cid
		});
	});

	mui("#slider").on('tap', 'a', function() {
		var type = this.getAttribute('type');
		var url = this.getAttribute("url");

		if("" != url) {
			if(1 == type) {
				mui.openWindow({
					url: "pdp.html?sid=" + url
				});
			} else if(2 == type) {
				location.href="dahua://openweb?"+url;
			}
		}

	});
          
});
